﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using Newtonsoft.Json;

public partial class Industry : Basic
{
    public string strYMHYPH = "";
    public string str01 = "";
    public string str02 = "";
    public string str03 = "";  //行业一指化分析报告
    public string strJQGZBK = "";  //近期关注板块
    protected void Page_Load(object sender, EventArgs e)
    {
        strJQGZBK = sb近期关注板块().ToString();

        str02 = sb头条().ToString();

        str01 = sb新闻列表("0801", 6).ToString() + sb新闻列表("0802", 6).ToString();

        strYMHYPH = sb益盟行业排行().ToString();

    }

    protected StringBuilder sb益盟行业排行()
    {
        StringBuilder sb = new StringBuilder();
        StringBuilder sb2 = new StringBuilder();
        try
        {
            string url = jsonUrl + "hangqing/hybk.ashx";
            string str = Pub.LoadData(url);
            List<IndustryEnty> obj = JsonConvert.DeserializeObject<List<IndustryEnty>>(str);

            if (obj != null)
            {
                sb.AppendLine("<table width=\"960\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" id=\"hyph\">");
                sb.AppendLine("<thead>");
                sb.AppendLine("<tr bgcolor=\"#ebf3f7\">");
                sb.AppendLine("<td width=\"47\" class=\"biankuang\">排名</td>");
                sb.AppendLine("<td width=\"54\" class=\"biankuang\">板块名称</td>");
                sb.AppendLine("<td width=\"54\" class=\"biankuang\">涨跌幅</td>");
                sb.AppendLine("<td width=\"64\" class=\"biankuang\">5日涨跌</td>");
                sb.AppendLine("<td width=\"91\" class=\"biankuang\">主力净买</td>");
                sb.AppendLine("<td width=\"91\" class=\"biankuang\">5日净买</td>");
                sb.AppendLine("<td width=\"54\" class=\"biankuang\">操盘线</td>");
                sb.AppendLine("<td width=\"72\" class=\"biankuang\">股票数量</td>");
                sb.AppendLine("<td width=\"72\" class=\"biankuang\">上涨家数</td>");
                sb.AppendLine("<td width=\"72\" class=\"biankuang\">下跌家数</td>");
                sb.AppendLine("<td width=\"91\" class=\"biankuang\">换手</td>");
                sb.AppendLine("<td width=\"43\" class=\"biankuang gray\">资讯</td>");
                sb.AppendLine("</tr>");
                sb.AppendLine("</thead>");
                sb.AppendLine("<tbody>");
                int i = 0;
                foreach (var m in obj)
                {
                    i++;
                    string _class = " bgcolor=\"#f2f2f2\"";
                    if ((i % 2) == 0)
                        _class = " #fff";
                    sb.AppendLine("<tr aa=\"1\" " + _class + ">");
                    sb.AppendLine("<td bgcolor=\"#f2f2f2\" class=\"h3\">" + i + "</td>");
                    sb.AppendLine("<td ><a href=\"" + quoteUrl + "bk" + m.C + ".shtml\" class=\"b\">" + m.N + "</a></td>");
                    sb.AppendLine("<td class=\"red\">" + OTO.PerRedGre(m.F, 2, "-", "%") + "</td>");
                    sb.AppendLine("<td class=\"green\">" + OTO.PerRedGre(m.F5, 2, "-", "%") + "</td>");
                    sb.AppendLine("<td>" + OTO.RedGre(OTO.CoUt(m.J, 10000, "-"), "-", "万元") + "</td>");
                    sb.AppendLine("<td>" + OTO.RedGre(OTO.CoUt(m.J5, 100000000, "-"), "-", "亿元") + "</td>");
                    sb.AppendLine("<td class=\"red\">" + m.BCount + "</td>");
                    sb.AppendLine("<td>" + m.Count + "</td>");
                    sb.AppendLine("<td class=\"red\">" + m.UpCount + "</td>");
                    sb.AppendLine("<td class=\"green\">" + m.DownCount + "</td>");
                    sb.AppendLine("<td>" + m.I + "</td>");
                    sb.AppendLine("<td>-</td>");
                    sb.AppendLine("</tr>");
                    sb.AppendLine("<tr aa=\"2\" style=\"display:none;\">");
                    sb.AppendLine("<td bgcolor=\"#f2f2f2\">&nbsp;</td>");
                    sb.AppendLine("<td colspan=\"13\" bgcolor=\"#f2f2f2\"><table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"10\" bgcolor=\"#FFFFFF\">");
                    sb.AppendLine("<tr>");
                    sb.AppendLine("<td><div class=\"hy_hyph_bg blue t_left\">可关注股票</div></td>");
                    sb.AppendLine("<td width=\"36%\" align=\"left\">");
                    foreach (var n in m.Other.Stocks)
                    {
                        sb.AppendFormat("<a href=\"{2}gg{0}.shtml\" class=\"b\">{1}</a> ", n.Code, n.StockName, quoteUrl);
                    }
                    sb.AppendLine("&nbsp;</td>");
                    sb.AppendLine("<td width=\"13%\" align=\"left\"><div class=\"hy_hyph_bg blue\">行业状况</div></td>");
                    sb.AppendLine("<td width=\"40%\" align=\"left\">" + OTO.CutStr(m.Other.Hyzk,50) + "</td>");
                    sb.AppendLine("</tr>");
                    sb.AppendLine("<tr>");
                    sb.AppendLine("<td height=\"1\" colspan=\"2\" align=\"left\" bgcolor=\"#CCCCCC\"></td>");
                    sb.AppendLine("<td height=\"1\" colspan=\"2\" align=\"left\" bgcolor=\"#CCCCCC\"></td>");
                    sb.AppendLine("</tr>");
                    sb.AppendLine("<tr>");
                    sb.AppendLine("<td align=\"left\"><div class=\"hy_hyph_bg blue\">投资要点</div></td>");
                    sb.AppendLine("<td align=\"left\">" + m.Other.Tzyd + "</td>");
                    sb.AppendLine("<td align=\"left\"><div class=\"hy_hyph_bg blue\">行业新闻</div></td>");
                    sb.AppendLine("<td align=\"left\">" + m.Other.Hyxw + "</td>");
                    sb.AppendLine("</tr>");
                    sb.AppendLine("</table></td>");
                    sb.AppendLine("</tr>");

                    //
                    str03 = sb2.AppendFormat("<li><a href=\"{1}bk{2}.shtml\" class=\"b\">{0}</a></li>", m.N, quoteUrl, m.C).ToString();
                }
                sb.AppendLine("</tbody>");

                sb.AppendLine("</table>");

            }
        }
        catch { }
        return sb;
    }

    protected StringBuilder sb新闻列表(string CID, int len)
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string url = jsonUrl + "news/NewsList.ashx?typeid=" + CID + "";
            string str = Pub.LoadData(url);
            NewsList obj = JsonConvert.DeserializeObject<NewsList>(str);

            if (obj != null)
            {
                sb.AppendLine("<div class=\"hangye_left_1 h3 red\">" + obj.typename + "<span class=\"hangye_more\"><a href=\"" + GetNewListUrl("03", CID, 1) + "\" class=\"b\">更多>></a></span></div>");
                sb.AppendLine("<div class=\"hangye_content_c\">");
                sb.AppendLine("<ul>");
                int i = 0;
                foreach (var item in obj.list)
                {
                    i++;
                    sb.AppendLine("<li> ·<a href=\"" + GetNewsUrl("03", CID, item.Id) + "\" title=\"" + item.Title + "\">" + item.Title + "</a> </li>");
                    if (i >= len)
                        break;
                }
                sb.AppendLine("</ul>");
                sb.AppendLine("</div>");
            }
        }
        catch { }
        return sb;
    }

    protected StringBuilder sb近期关注板块()
    {
        StringBuilder sb = new StringBuilder();
        //try
        //{
        string url = jsonUrl + "comm/JQGZGP.ashx";
        string str = Pub.LoadData(url);
        List<Gzbk> obj = JsonConvert.DeserializeObject<List<Gzbk>>(str);

        if (obj != null)
        {
            obj = obj.Take(3).ToList();

            sb.Append("<div class=\"hangye_right\">");
            sb.Append("<div class=\"hangye_right_top\">");
            sb.Append("<div class=\"hy_t_l h3\">近期关注板块</div>");
            sb.Append("<ul id=\"ul_gzbk\">");
            int i = 0;
            foreach (var m in obj)
            {
                i++;
                if (i == 1)
                    sb.Append("<li class=\"white_bg center h3\" id=\"gzbk_li_" + i + "\">" + m.BKName + "</li>");
                else
                    sb.Append("<li class=\"center h3\">" + m.BKName + "</li>");
            }
            sb.Append("</ul>");
            sb.Append("<div class=\"hy_t_r center \"><a href=\"BkCalendar.aspx\"><img src=\"http://down3.emstock.com.cn/www/images/hangye/hangye_rmbkrl.png\" /></a></div>");
            sb.Append("</div>");

            i = 0;
            foreach (var m in obj)
            {
                string _class = "hy_bk_b";
                string _display = "";
                i++;
                if (i > 1)
                {
                    _class = "hy_bk_n";
                    _display = "style=\"display:none;\"";
                }
                sb.Append("<div class=\"" + _class + "\" gz_show=\"b\" id=\"bk_" + m.BKName + "\" " + _display + " >");
                sb.Append("<div style=\"padding:5px 20px;\">");
                sb.Append("<h2>" + m.BKName + "行业</h2>");
                sb.AppendFormat("{0}", OTO.CutStr(m.News.Content, 80));
                sb.Append("</div>");
                sb.Append("<div class=\"hangye_right_zs\">(此信息来源于益盟高端信息资讯软件-<a href=\"http://www.emstock.com.cn/djc/index.html\" class=\"b\">睿讯通</a>，睿讯通体验申请热线400-670-7799)</div>");
                sb.Append("<div class=\"hy_r_z\">");
                sb.AppendFormat("<div class=\"hy_r_top\">{0}行业走势</div>", m.BKName);
                sb.Append("<img src=\"" + quoteImgUrl + "?id=" + m.BKID + "&&t=4&p=1&i=vol&w=269&h=126&c=16&rr=" + Math.Round(10.00) + "\" /> </div>");
                //sb.Append("<img src=\"images/hangye/hangye_t1.png\" /> </div>");
                sb.Append("<div class=\"hy_r_z\">");
                sb.AppendFormat("<div class=\"hy_r_top\">{0}行业要闻</div>", m.BKName);
                sb.Append("<ul>");
                foreach (var n in m.NewsLst)
                {
                    sb.AppendFormat("<li>·<a href=\"{0}\" class=\"b\" title=\"{1}\">{1}</a></li>", GetNewsUrl("03", "0801", n.Id), n.Title);
                }
                sb.Append("</ul>");
                sb.Append("</div>");
                sb.Append("<div class=\"hy_r_k\">");
                sb.AppendFormat("<div class=\"hy_r_top\">行业可关注股票</div>", m.BKName);
                sb.Append("<ul>");
                foreach (var n in m.Stocks)
                {
                    if (n.News != null)
                        sb.AppendFormat("<li><span><a href=\"{4}gg{0}.shtml\" class=\"b\">{1}</a></span><a href=\"{3}\" >{2}</a></li>", n.Code, n.Name, n.News.Title, GetNewsUrl("03", "0305", n.News.Id), quoteUrl);
                }
                sb.Append("</ul>");
                sb.Append("</div>");
                sb.Append("<div style=\"clear:both;\"></div>");
                sb.Append("</div>");
            }
            sb.AppendLine("</div>");

        }
        //}
        //catch
        //{
        //    sb = new StringBuilder();
        //}
        return sb;
    }

    protected StringBuilder sb头条()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string str = Pub.LoadData(jsonUrl + "news/Headline.ashx?id=hy_1");
            NewsHeadEnty obj = JsonConvert.DeserializeObject<NewsHeadEnty>(str);
            if (obj != null)
            {
                sb.AppendFormat("<li class=\"h2 center\"><a href=\"{1}\" class=\"b\">{0}</a></li>", obj.Title, obj.Url);
                sb.AppendFormat("<li class=\"font12 gray\">{0}<a href=\"{1}\" class=\"r\">[详细]</a></li>", obj.Content, obj.Url);
            }
        }
        catch { }
        return sb;
    }
}